// plugins/globalMethods.client.js

// 定义格式化方法
export function formatCount (count) {
    if (count < 1000) {
        return count.toString();
    } else if (count >= 1000 && count < 10000) {
        const w = Math.floor(count / 1000);
        return w + 'k';
    } else if (count >= 10000) {
        const w = Math.floor(count / 10000);
        return w + 'w';
    }
}

// 定义日期格式化方法
export function  formatDate (dateString){
    if (!dateString) {
        const today = new Date();
        const year = today.getFullYear();
        const month = String(today.getMonth() + 1).padStart(2, '0');
        const day = String(today.getDate()).padStart(2, '0');
        return `${year}-${month}-${day}`;
    }

    const date = new Date(dateString);
    const now = new Date();
    const diffTime = Math.abs(now - date);
    const diffDays = Math.floor(diffTime / (1000 * 60 * 60 * 24));

    if (diffDays === 0) {
        const diffHours = Math.floor(diffTime / (1000 * 60 * 60));
        if (diffHours === 0) {
            const diffMinutes = Math.floor(diffTime / (1000 * 60));
            return `${diffMinutes} 分钟前`;
        }
        return `${diffHours} 小时前`;
    } else if (diffDays < 7) {
        return `${diffDays} 天前`;
    } else {
        const year = date.getFullYear();
        const month = String(date.getMonth() + 1).padStart(2, '0');
        const day = String(date.getDate()).padStart(2, '0');
        return `${year}-${month}-${day}`;
    }
}


